//
//  YJMoreViewController.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/23.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJMoreViewController.h"
#import "MoreModel.h"
#import "YJReportListcell.h"
#import "YJHeaderController.h"
@interface YJMoreViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)NSMutableArray *dataarray;

@end

@implementation YJMoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataarray =[[NSMutableArray alloc] init];
    [self createTableView:@"YJReportListcell"];
    self.tableView.rowHeight =180;
    [self.view addSubview:self.tableView];
    [self createHttpRequest];
    [self createData];
    
}

-(void)createData{
    __weak typeof(self)weakSelf =self;
    [self.manager GET:kMoreUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            NSDictionary*dicts =[NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
            NSDictionary *data =dicts[@"data"];
            NSArray *array = data[@"list"];
            for (NSDictionary *dict in array) {
                MoreModel *model =[[MoreModel alloc] init];
                [model setValuesForKeysWithDictionary:dict];
                [weakSelf.dataarray addObject:model];
            }
            [weakSelf.tableView reloadData];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataarray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YJReportListcell *cell=[tableView dequeueReusableCellWithIdentifier:@"YJReportListcell" forIndexPath:indexPath];
    MoreModel *model =self.dataarray[indexPath.row];
    [cell showDataWithmormModel:model];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YJHeaderController *controller =[[YJHeaderController alloc] init];
    MoreModel *model =self.dataarray[indexPath.row];
    controller.linkUrl=model.linkUrl;
    [self.navigationController pushViewController:controller animated:YES];
}


@end
